var database = require('../../../data/data.js')
Page({
  data: {
  },
  onLoad: function (options) {
    this.setData({
      id: options.id
    })
    var that = this;
    wx.request({
      url: database.url + '/project/getCarousel.action',
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
      },
      success: function (res) {
        console.log(res.data)
        for (var i = 0; i < res.data.length; i++) {
          if (res.data[i].id == options.id) {
            var detail = res.data[i].introduce
            var title = res.data[i].title
            var writer = res.data[i].writer
            var views = res.data[i].views
            var time = res.data[i].time
            var id = res.data[i].id
            var img = res.data[i].img
            if (res.data[i].videourl != null) {
              var video = res.data[i].videourl
            }
            if (res.data[i].picture){
              var picture = res.data[i].picture
            }
          }
        }
        var re = detail
        re.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match) {
           var ree = match.replace("<img ", "<img mode='widthFix' style='width:100%;' ")
          re = re.replace(match, ree)
        });
        detail = re
        that.setData({
          picture: picture,
          detail: detail,
          title: title,
          video: video,
          writer: writer,
          view: views,
          time: time,
          img:img
        })
      }
    })
  },
  onShareAppMessage() {
    var that = this;
    return {
      title: that.data.title,
      imageUrl: that.data.img,
      path: '/pages/home/swiper_detail/swiper_detail?id=' + that.data.id,
      success: function (res) {
        wx.showToast({
          title: '转发成功',
          icon: 'success',
          duration: 1500
        })
      }
    }
  }
})